package com.example.demo.common;

import com.example.demo.entity.User;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

/**
 * 获取当前登录用户的session信息
 */
public class UserSessionUtils {
    public static User getUserSession(HttpServletRequest request) {

        HttpSession session = request.getSession(false);
        if(session != null && session.getAttribute(AppVariable.USER_SESSION_KEY) != null) {
            return (User)session.getAttribute(AppVariable.USER_SESSION_KEY);
        }
        return  null;
    }
}
